
function getRandom(len){
	//default 4 bit lenth; 1000~9999 < Short.MAX_VALUE=32676
	var p = parseInt(len)?parseInt(len):4; 
		p = (p>20)?20:(p-1);
	var r = Math.pow(10,p)*(9*Math.random()+1);
	return Math.floor(r);
}

function parseNumber(aNumber){
	// -Number.MAX_VALUE ≈-1.79E+308;
	//  Number.MAX_VALUE ≈ 1.79E+308;
	//  Number.MIN_VALUE ≈ 2.22E-308;
	//  Number.POSITIVE_INFINITY 值显示为 infinity
	//  Number.NEGATIVE_INFINITY 值显示为 -infinity;
	// "∞","+∞","-∞";
	switch(typeof(aNumber)){
		case "number" : return aNumber;
		case "string" :	break;
		default : return NaN;
	}
	var returnNumber = NaN;
	var srcNumber=aNumber.replace(/\s/g,"");
		srcNumber=srcNumber.replace("+","");
	if(!isNaN(parseFloat(srcNumber))){
		if(srcNumber.indexOf(".")>-1){
			returnNumber = parseFloat(srcNumber);
		}else{
			returnNumber = parseInt(srcNumber);
		}
	}else{
		srcNumber=srcNumber.toUpperCase();
		if( (srcNumber.indexOf("-∞")>-1) ||
			(srcNumber.indexOf("-INFINITY")>-1) ||
			(srcNumber.indexOf("NEGATIVE_INFINITY")>-1) 
		){
			returnNumber = Number.NEGATIVE_INFINITY;
		}else if(
		 (srcNumber.indexOf("∞")>-1) ||
		 (srcNumber.indexOf("INFINITY")>-1)
		){
			returnNumber = Number.POSITIVE_INFINITY;
		}else if(
		 (srcNumber.indexOf("-NUMBER.MAX_VALUE")>-1) ||
		 (srcNumber.indexOf("-MAX_VALUE")>-1)
		){
			returnNumber = -Number.MAX_VALUE;
		}else if(
		 (srcNumber.indexOf("NUMBER.MAX_VALUE")>-1) ||
		 (srcNumber.indexOf("MAX_VALUE")>-1)
		){
			returnNumber = Number.MAX_VALUE;
		}else if(
		 (srcNumber.indexOf("-NUMBER.MIN_VALUE")>-1) ||
		 (srcNumber.indexOf("-MIN_VALUE")>-1)
		){
			returnNumber = -Number.MIN_VALUE;
		}else if(
		 (srcNumber.indexOf("NUMBER.MIN_VALUE")>-1) ||
		 (srcNumber.indexOf("MIN_VALUE")>-1)
		){
			returnNumber = Number.MIN_VALUE;
		}
	}
	return returnNumber;
}



function belongtoSection(aNumber,aSection){
	//section should like (2,4);[5,6];(5.8,8];[(4,0])
	if(!aSection)return false;
	var minTokenIndex = aSection.lastIndexOf("{");
	var maxTokenIndex = aSection.indexOf("}");
	if( minTokenIndex>-1 && maxTokenIndex>minTokenIndex	){
		//if multi sections include {}, invoke belongtoCollection();
		return belongtoCollection(aNumber,aSection);
	}
	var matched=false;
	var section=aSection.replace(/\s/g,"");
	var commaTokenIndex=Math.max( section.indexOf(","), section.indexOf(";") );
	var indexp = section.indexOf(")");//parenthesis;
	var indexb = section.indexOf("]");//square brackets
	maxTokenIndex = (indexp>-1&&indexb>-1)?Math.min(indexp,indexb):Math.max(indexp,indexb);
	minTokenIndex = Math.max( section.lastIndexOf("("), section.lastIndexOf("[") );
	//alert(aNumber+"@"+aSection+"\n"+minTokenIndex+","+commaTokenIndex+maxTokenIndex);
	if( minTokenIndex<0 ||
		commaTokenIndex<1 ||
		maxTokenIndex<2 ||
		minTokenIndex>=commaTokenIndex ||
		commaTokenIndex>=maxTokenIndex 
		){
		return matched;//false;
	}
	var minString, maxString;
	var minNumber, maxNumber;
	var srcNumber = parseNumber(aNumber);
	minString = section.substring(minTokenIndex+1,commaTokenIndex);
	maxString = section.substring(commaTokenIndex+1,maxTokenIndex);
	if(!minString){ minNumber = Number.NEGATIVE_INFINITY; }
	else{minNumber = parseNumber(minString);}
	if(!maxString){ maxNumber = Number.POSITIVE_INFINITY; }
	else{maxNumber = parseNumber(maxString);}
	if(isNaN(srcNumber)||isNaN(maxNumber)||isNaN(minNumber)){
		return matched;//false;
	}
		
	var minMatched = false, maxMatched = false;
	var minToken = section.substr(minTokenIndex,1);
	var maxToken = section.substr(maxTokenIndex,1);
	if( minToken=="(" ){
		minMatched = srcNumber > minNumber;
	}else if( minToken=="[" ){
		minMatched = srcNumber>= minNumber;
	}
	if( maxToken==")" ){
		maxMatched = srcNumber < maxNumber;
	}else if( maxToken=="]" ){
		maxMatched = srcNumber<= maxNumber;
	}
	//alert(minToken+minNumber+","+maxNumber+maxToken+"\n"+srcNumber+":"+minMatched+","+maxMatched);
	matched = minMatched && maxMatched;
	
	return matched;
	
}
